<template>
    <div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <button class="layui-btn" @click="addPrice()"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                <tr>
<!--                                    <th style="width: 10px;padding: 9px 5px">序号</th>-->
                                    <th>标题</th>
                                    <th>更新时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="item in priceData" >
<!--                                    <td>-->
<!--                                        {{item.id}}-->
<!--                                    </td>-->
                                    <td>
                                        <a @click.stop="openedit(item)" title="点击编辑该售价单" style="cursor: pointer;">{{item.title}}<span v-if="item.detail !== null && item.detail !== ''">(内有详情)</span></a>
                                        &nbsp;
                                        <a v-if="item.file !== null && item.file!=='' && (item.file.substr(item.file.lastIndexOf('.') + 1) === 'png' || item.file.substr(item.file.lastIndexOf('.') + 1) === 'jpg' || item.file.substr(item.file.lastIndexOf('.') + 1) === 'bmp')" class="layui-btn" @click="view(item.id)" href="javascript:;" style="background-color: #58B797">
                                            <i style="font-style: normal" title="点击查看图片" class="iconfont">&#xe6a8;</i>
                                        </a>
                                        <a v-if="item.file !== null && item.file!=='' && !(item.file.substr(item.file.lastIndexOf('.') + 1) === 'png' || item.file.substr(item.file.lastIndexOf('.') + 1) === 'jpg' || item.file.substr(item.file.lastIndexOf('.') + 1) === 'bmp')" class="layui-btn" @click="view(item.id)" href="javascript:;" style="background-color: #58B797">
                                            <i style="font-style: normal" title="点击下载文件" class="iconfont">&#xe714;</i>
                                        </a>
                                    </td>
                                    <td>
                                        {{item.dateDesc}}
                                    </td>
                                    <td class="td-manage">
                                        <a title="删除" class="layui-btn layui-btn-danger" @click="deletep(item.id)" href="javascript:;">
                                            <i class="layui-icon">&#xe640;</i>
                                        </a>

                                    </td>

                                </tr>
                                </tbody>
                            </table>
                            <my-page :total="count"></my-page>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

    import { mapActions, mapState } from "vuex";
    import page from './pagination4'
    import priceadd from './price-add'
    import priceedit from './price-edit'
    import service from "../../../src/service";

    export default {
        data(){
            return{
            }
        },
        name: "Pricetable",
        components:{
            'my-page':page
        },
        created() {
            this.getprice();
            this.getpriceCounts();
        },
        computed:{
            ...mapState({
                priceData:state=>state.priceData,
                count:state=>state.priceCount,
            })
        },
        methods:{
            // dateformat(time){
            //     var date=new Date(time);
            //     var year=date.getFullYear();
            //     var month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
            //     var day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
            //     var hours=date.getHours()<10 ? "0"+date.getHours() : date.getHours();
            //     var minutes=date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes();
            //     var seconds=date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds();
            //     // 拼接
            //     return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
            // },
            deletep(id){
                let vm = this;
                layer.confirm('确认删除该条售价信息？',function(){
                    vm.deletePrice(id);
                    setTimeout(vm.getprice,500);
                    setTimeout(vm.getpriceCounts,500);
                });
            },
            openedit(item){
                this.$layer.open({
                    id:1,
                    type:2,
                    content: {
                        content: priceedit, //传递的组件对象
                        parent: this,//当前的vue对象
                        data:{price:item}//props
                    },
                    area:['500px','680px'],
                    title: '编辑售价表',
                    maxmin: true,
                });
            },
            addPrice(){
                this.$layer.open({
                    id:1,
                    type:2,
                    content: {
                        content: priceadd, //传递的组件对象
                        parent: this,//当前的vue对象
                    },
                    area:['500px','600px'],
                    title: '添加售价表信息',
                    maxmin: true,
                });
            },
            view(id){
                service.instance().get("http://"+window.location.hostname+":8011/price/getSuffix/"+id).then((response)=> {
                    if(response.data === "picture"){
                        xadmin.open('附件图片预览',"http://"+window.location.hostname+":8011/price/getpic/"+id,"","",true)
                    }
                    else{
                        window.location.href = "http://"+window.location.hostname+":8011/price/getfile/"+id
                    }
                }).catch((error)=> {
                                 });

            },
            ...mapActions(["getprice","getpriceCounts","deletePrice"])
        },
        mounted(){
        },
    }


</script>

<style scoped>

</style>